package com.yyk.yykywd.mvvm.ui.fragment

import android.os.Bundle
import androidx.lifecycle.Observer
import com.orhanobut.logger.Logger
import com.yyk.yykywd.*
import com.yyk.yykywd.base.BaseFragment
import com.yyk.yykywd.mvvm.entity.WorkNumBean
import com.yyk.yykywd.mvvm.ui.AddCustomerActivity
import com.yyk.yykywd.mvvm.ui.MarketingMaterialActivity
import com.yyk.yykywd.mvvm.view_model.NewWorkViewModel
import com.yyk.yykywd.util.ToAnotherActivity
import com.yyk.yykywd.util.ToastUtil
import kotlinx.android.synthetic.main.fragment_new_work.*

/**
 * 文件描述：
 * Created by guo on 2019-11-19.
 */
class NewWorkFragment : BaseFragment() {
    private lateinit var viewmodel: NewWorkViewModel

    companion object {
        const val TAG = "NewWorkFragment"
    }

    override fun initData() {
        viewmodel.getNum()
    }

    override fun getLayoutId(): Int {
        return R.layout.fragment_new_work
    }

    override fun setListener() {
        super.setListener()

        viewmodel.workNum.observe(this, Observer<WorkNumBean> {
            tv_return_money_num.text = it.data.getmoneyokcount.toString()
            tv_install_hospital_num.text = it.data.hoscount.toString()
        })

        cl_returned_money.setOnClickListener {
            ToAnotherActivity.toReturnMoneyActivity(requireActivity(), FROM_RETURN_MONEY_AGENT)
        }
        cl_install_hospital.setOnClickListener {
            ToAnotherActivity.toReturnMoneyActivity(requireActivity(), FROM_INSTALL_HOSPITAL)
        }
        cl_meeting_invitation.setOnClickListener {
            ToAnotherActivity.toMeetingInvitationActivity(requireActivity(), FROM_WORK)
        }
        cl_market_material.setOnClickListener {
            ToAnotherActivity.toCommonActivity(requireActivity(), MarketingMaterialActivity::class.java)
        }
        cl_add_customer.setOnClickListener {
            if (whetherHavePermission()) {
                return@setOnClickListener
            }
            ToAnotherActivity.toCommonActivity(requireActivity(), AddCustomerActivity::class.java)
        }
        cl_potential_customer.setOnClickListener {
            if (whetherHavePermission()) {
                return@setOnClickListener
            }
            ToAnotherActivity.toPotentialCustomerActivity(requireActivity(), POTENTIAL_CUSTOMER)
        }
        cl_c_customer.setOnClickListener {
            if (whetherHavePermission()) {
                return@setOnClickListener
            }
            ToAnotherActivity.toPotentialCustomerActivity(requireActivity(), C_CUSTOMER)
        }
        cl_sign_contract.setOnClickListener {
            if (whetherHavePermission()) {
                return@setOnClickListener
            }
            ToAnotherActivity.toPotentialCustomerActivity(requireActivity(), SIGN_CONTRACT)
        }
    }

    override fun initView() {
        viewmodel = getFragmentViewModel(this, NewWorkViewModel::class.java)
    }

    override fun interfaceIsVisible() {
        super.interfaceIsVisible()
        viewmodel.getNum()
    }
}